package com.ddxz.hetong.controller;

import com.ddxz.hetong.service.HeTongService;
import com.ddxz.tool.web.dto.DdxzResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * description
 *
 * @author 朱宗刚
 * @version 1.0.0
 * @date 2022/7/7
 */

@RestController
@RequestMapping("/unity/hetong")
@Api("合同相关接口")
public class HeTongController {

    @ApiOperation(value = "合同总额", notes = "根据类型不同，获取对应的合同总额; 1 融资合同；2 工程合同; 3 设备合同")
    @RequestMapping(value = "/total", method = RequestMethod.GET)
    public DdxzResponse getTotalMoney(@RequestParam(name = "type") Integer type) {
        return service.getTotalMoney(type);
    }

    @ApiOperation(value = "获取贷款机构列表", notes = "获取贷款机构列表，包含贷款机构名称，合同名称，合同总额;" +
            "status: 0 获取所有单位的列表，忽略deptName和year参数； 1 获取所有的借款年份列表，忽略deptName和year参数；" +
            "    2 获取单位下的借款年份列表，忽略year参数； 3 获取借款年份下的单位列表，忽略deptName参数；" +
            "    4 获取详情数据，deptName和year都不可忽略； 5 获取所有还款年份列表，忽略deptName和year参数；" +
            "  6 获取单位下的还款年份列表，忽略year参数； 7 获取还款年份下的单位列表，忽略deptName参数；" +
            "  8 获取详情数据；   9 获取单位、借款年份下的月度汇总情况；" +
            " 10 获取单位、还款年份下的月度汇总；      11 获取借款年份下的月度汇总；" +
            " 12 获取还款年份下的月度汇总")
    @RequestMapping(value = "/dept/list", method = RequestMethod.GET)
    public DdxzResponse getDeptYearList(@RequestParam(name = "status", required = false) Integer status,
                                        @RequestParam(name = "deptName", required = false) String deptName,
                                        @RequestParam(name = "year", required = false) Integer year,
                                        @RequestParam(name = "month", required = false) String month,
                                        @RequestParam(name="pageSize", required = false, defaultValue = "10") Integer pageSize,
                                        @RequestParam(name="pageNum", required = false, defaultValue = "1") Integer pageNum) {
        return service.getDeptList(status, deptName, year, pageSize, pageNum);
    }

    @ApiOperation(value = "贷款机构以发放比例", notes = "以贷款金额占合同总额的比例")
    @RequestMapping(value = "/dept/percent", method = RequestMethod.GET)
    public DdxzResponse getDeptPercent(@RequestParam(name = "type", required = false) Integer type) {
        return service.getDaptPercent(type);
    }

    @ApiOperation(value = "设备/合同列表", notes = "status 控制查询方式具体方式如下" +
            "0 查询所有的单位和合同列表，deptName和protoName会被忽略；" +
            "1 查询指定单位的合同列表，protoName会被忽略；" +
            "2 查询详情列表，deptName和protoName都会被使用")
    @RequestMapping(value = "/device/list", method = RequestMethod.GET)
    public DdxzResponse getDeviceDeptList(@RequestParam(name = "status", required = false, defaultValue = "0") Integer status,
                                          @RequestParam(name = "deptName", required = false) String deptName,
                                          @RequestParam(name = "protoName", required = false) String protoName,
                                          @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                          @RequestParam(name = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
        return service.getDeviceDeptList(status, deptName, protoName, pageSize, pageNum);
    }

    @ApiOperation(value = "工程/合同列表", notes = "status 控制查询方式，具体方式如下：" +
            "0. 以所有单位的汇总，忽略deptName和year参数； 1. 所有年份的汇总，忽略deptName和year参数； " +
            "2. 单位下所有年份的汇总，忽略year参数； 3. 年份下所有单位的汇总，忽略deptName参数；" +
            "4. 查看年份下的月度汇总，忽略deptName;  5. 查看单位及年份组合下的月份汇总；" +
            "6. 查看详细表单数据;     7. 查看合同列表")
    @RequestMapping(value = "/project/list", method = RequestMethod.GET)
    public DdxzResponse getProjectList(@RequestParam(name = "status", required = false, defaultValue = "0") Integer status,
                                       @RequestParam(name = "deptName", required = false) String deptName,
                                       @RequestParam(name = "protoName", required = false) String protoName,
                                       @RequestParam(name = "year", required = false) Integer year,
                                       @RequestParam(name = "month", required = false) String month,
                                       @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
        return service.getProjectList(status, deptName, protoName, year, month, pageNum, pageSize);
    }

    @ApiOperation(value = "进度详情", notes = "根据进度的百分比获取对应的详情列表，需要分页展示；" +
            "0: 0-20%； 1: 20%-40%; 2: 40%-60%; 3: 60%-80%; 4: 80%-100%")
    @RequestMapping(value = "/percent/detail", method = RequestMethod.GET)
    public DdxzResponse getDevicePercentDetail(@RequestParam(name = "status", required = false, defaultValue = "0") Integer status,
                                               @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                               @RequestParam(name = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
        return service.getDevicePercentDetail(status, pageNum, pageSize);
    }

    @ApiOperation(value = "进度列表", notes = "获取不同进度下的合同个数，枚举值如下：" +
            "0: 0-20%； 1: 20%-40%; 2: 40%-60%; 3: 60%-80%; 4: 80%-100%")
    @RequestMapping(value = "/percent/list", method = RequestMethod.GET)
    public DdxzResponse getDevicePercentList() {
        return service.getDevicePercentList();
    }

    @ApiOperation(value = "合同列表", notes = "以合同为维度，统计总额，支付金额，发票金额，未开票金额")
    @RequestMapping(value = "/device/proto/list", method = RequestMethod.GET)
    public DdxzResponse getDeviceProtoList(@RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                           @RequestParam(name = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
        return service.getDeviceProtoList(pageNum, pageSize);
    }

    private final HeTongService service;

    public HeTongController(HeTongService service) {
        this.service = service;
    }
}
